package com.tow.group.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tow.group.bean.User;
import com.tow.group.dao.DatabaseDao;
import com.tow.group.dao.IDatabaseDao;

public class LoginServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		String name = request.getParameter("name");
		String pwd = request.getParameter("pwd");
		System.out.println(name + pwd);
		User user = new User();
		user.setUser_Name(name);
		user.setPassWord(pwd);
		
		IDatabaseDao login =new DatabaseDao();
		try {
			boolean flag = login.login(user);
			System.out.println(flag);
			if(flag){
				request.setAttribute("name", name);
				request.getRequestDispatcher("/qq_sy.jsp").forward(request, response);
			}else{
				response.sendRedirect("/Tencent/qq_sy.jsp");	
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
